// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'
import Client from '@api/sparepartshospital/api/SpareDashboardApi'

import InfoClass from '@api/sparepartshospital/model/SpareStockOverviewReq'

const CLIENT = CORE.grpcCLIENT(Client)

// ============================== 导出远程接口 ============================== //

export default {
  // —————————————————————————————— 信息 —————————————————————————————— //

  validInfoParam(infoParam) {
    return infoParam.warehouseId
  },
  async getInfo(param, TIP = '查询统计数量') {
    const DTO = CORE.grpcDTO(InfoClass, param)
    const resp = await CORE.grpc(TIP, CLIENT, 'querySpareStockOverview', DTO)
    return resp.content || []
  },
  transInfo(arr = [], { state: { info } }) {
    const valueList = info.keyList.map((key) => {
      const matched = arr.find((item) => item.name === key) || {}
      return matched.value || 0
    })
    return { valueList }
  },
}
